home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / plain / contrib / calendar.tex < prev    next >
Encoding:
Text File  |  1992-08-26  |  3.2 KB  |  75 lines

  1. \magnification=1000
  2. \hoffset=0.25 true in\voffset=-0.85 true in
  3. \vsize=8.0 true in\hsize=7.8 true in % This is for landscape format
  4. \nopagenumbers\topskip=0pt\parindent=0 pt\offinterlineskip
  5. \font\medrm=cmr10 at 10.95 pt
  6. \font\bigrm=cmr10 at 24.88 pt
  7.  
  8. % This method is based on the facts that the Gregorian year 1752 was
  9. % a leap year which began on Saturday (it was also the year the
  10. % British adopted the Gregorian calendar) and that each year of 365 days
  11. % advances through the cycle of the week by one day.
  12. \newcount\month \newcount\monthoff \newcount\year \newcount\yearoff
  13. \newcount\daycount \newcount\monthdays \newcount\date
  14. \newcount\leap \newcount\numleaps \newcount\lyear
  15. \newcount\cyear \newcount\qyear
  16. \newcount\temp \newcount\test \newcount\row \newcount\col
  17. \def\mod#1#2to#3{\temp=-#1\divide\temp by #2\multiply\temp by #2
  18.   \advance\temp by #1 #3=\temp}
  19. \def\spellmonth{\ifcase\month
  20.   \or January\or February\or March\or April\or May\or June
  21.   \or July\or August\or September\or October\or November\or December\fi}
  22. \immediate\write1{}
  23. \message{Number of month: } \read -1 to \month
  24. \message{Year: } \read -1 to \year
  25. \ifnum\year<1753 \message{Can't make calendars for earlier than 1753}\end\fi
  26. \temp=\year \advance\temp by -1 \yearoff=\temp \advance\yearoff by -1752
  27. \numleaps=\temp \divide\numleaps by 4
  28. \test=\temp \divide\test by 100 \advance\numleaps by -\test
  29. \test=\temp \divide\test by 400 \advance\numleaps by \test
  30. \advance\numleaps by -424 % That is the number of offset days for 1752.
  31. \advance\yearoff by \numleaps \mod{\yearoff}{7}to{\date}
  32. % The day of the week of the first day of the month is similarly determined
  33. % after first determining whether it is a leap year.  \leap is set to 0 if
  34. % it is not and 1 if it is a leap year.
  35. \leap=0
  36. \mod{\year}{4}to{\lyear}
  37. \mod{\year}{100}to{\cyear}
  38. \mod{\year}{400}to{\qyear}
  39. \ifnum\lyear=0 \ifnum\cyear=0 \ifnum\qyear=0 \leap=1\fi
  40.                \else \leap=1\fi\fi
  41. \monthdays=\ifcase\month 0\or 31\or 28\or 31\or 30\or 31\or 30
  42.   \or 31\or 31\or 30\or 31\or 30\or 31\fi
  43. \daycount=\ifcase\month 0\or 0\or 31\or 59\or 90\or 120\or 151
  44.   \or 181\or 212\or 243\or 273\or 304\or 334\fi
  45. \ifnum\month=2 \advance\monthdays by \leap
  46.   \else \ifnum\month>2 \advance\daycount by \leap\fi\fi
  47. \mod{\daycount}{7}to{\monthoff}
  48. \test=\date \advance\test by \monthoff \mod{\test}{7}to{\date}
  49. \date=-\date
  50.  
  51. \newbox\lodate \setbox\lodate=\vbox to1.1in{\vfil\hrule height1pt width1.1in}
  52. \newbox\hidate \setbox\hidate=\null \ht\hidate=1.1in \wd\hidate=1.1in
  53. \newdimen\loht \loht=1.1 in \advance\loht by -1pt
  54. \def\head#1{\hbox to1.1in{\hfil#1\hfil}}
  55. \def\doday{\global\advance\date by1
  56.   \ifnum\date<1\copy\lodate
  57.   \else\ifnum\date>\monthdays\copy\hidate
  58.     \else\ifnum\date=1\vrule height1.1in width1pt\fi
  59.     \vbox{\ifnum\row=1\hrule height1pt\fi\hbox to1.1in{\hfil
  60.     \raise60pt\hbox{\number\date}\kern10pt
  61.     \vrule height\loht width1pt}\hrule height1pt}\fi\fi}
  62.  
  63. \centerline{\bigrm\spellmonth\ \number\year}
  64. \vskip0.35in
  65. \line{\medrm\head{Sunday}\head{Monday}\head{Tuesday}\head{Wednesday}
  66.   \head{Thursday}\head{Friday}\head{Saturday}\hss}
  67. \vskip0.15in
  68. \row=1
  69. \loop
  70. \line{\col=1
  71.   \ifnum\row>1\ifnum\date<\monthdays\vrule height1.1in width1pt\fi\fi
  72.   \loop\doday\advance\col by1\ifnum\col<7\repeat\hss}
  73. \advance\row by1\ifnum\row<6\repeat
  74. \bye
  75.